#include <gtest/gtest.h>
#include <algorithm>

using namespace std;

int maxDiff(const vector<int>& vec)
{
  unsigned int current_max_diff = 0;
  auto len = vec.size();
  for (unsigned int i = 0; i < len; ++i)
  {
    for (unsigned int j = len - 1; j > i; --j)
    {
      if (vec.at(i) < vec.at(j))
      {
        if (current_max_diff < j - i)
          current_max_diff = j - i;
      }
    }
  }
  return current_max_diff;
}

int main(int argc, char **argv)
{
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();

  vector<int> numbs = { 11, 1, 13, 14, 7, 8, 9, 10 };

  cout << maxDiff(numbs) << endl;
}

//----------------------------------GTESTS------------------------------------

TEST(MaxDiff, Test1) {

  vector<int> numbs = { 10, 11, 3, 8, 5, 9, 4 };

  ASSERT_EQ(4, maxDiff(numbs));
}

TEST(MaxDiff, Test2) {

  vector<int> numbs = { 2, 11, 3, 8, 5, 9, 1 };

  ASSERT_EQ(5, maxDiff(numbs));
}

TEST(MaxDiff, Test3) {

  vector<int> numbs = { 10, 11, 12, 3, 4, 2, 1 };

  ASSERT_EQ(2, maxDiff(numbs));
}

TEST(MaxDiff, Test4) {

  vector<int> numbs = { 13, 12, 11, 3, 4, 2, 1 };

  ASSERT_EQ(1, maxDiff(numbs));
}


TEST(MaxDiff, Test5) {

  vector<int> numbs = { 13, 12, 11, 9, 3, 4, 2, 14, 10 };

  ASSERT_EQ(7, maxDiff(numbs));
}


//----------------------------------extreme_cases:)------------------------------

TEST(MaxDiff, TestEmpty) {

  vector<int> numbs = {};

  ASSERT_EQ(0, maxDiff(numbs));
}

TEST(MaxDiff, TestRepeatElem) {

  vector<int> numbs = { 13, 12, 13, 9, 3, 4, 13, 14, 10 };

  ASSERT_EQ(7, maxDiff(numbs));
}


TEST(MaxDiff, TestSameElem) {

  vector<int> numbs = { 4, 4, 4, 4, 4, 4, 4 };

  ASSERT_EQ(0, maxDiff(numbs));
}


TEST(MaxDiff, TestDownFallingEl) {

  vector<int> numbs = { 14, 13, 12, 11, 10, 9 };

  ASSERT_EQ(0, maxDiff(numbs));
}


TEST(MaxDiff, TestBinaryElem) {

  vector<int> numbs = { 0, 1, 0, 1, 0, 1, 0, 1 };

  ASSERT_EQ(7, maxDiff(numbs));
}

TEST(MaxDiff, KostyaKontrTest) {

  vector<int> numbs = { 11, 1, 13, 14, 7, 8, 9, 10 };

  ASSERT_EQ(6, maxDiff(numbs));
}